package com.ozo.cloud.common.database.util;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.HashMap;
import java.util.Map;

/**
 * 代码生成工具类
 *
 * @author qiangesoft
 * @date 2024-09-05
 */
public class CodeGenerationUtils {

    public static void main(String[] args) {
        String projectPath = System.getProperty("user.dir");

        Map<OutputFile, String> map = new HashMap<>();
        map.put(OutputFile.xml, projectPath + "/ozo-cloud-system" + "/src/main/resources/mapper");

        // 使用 FastAutoGenerator 快速配置代码生成器
        FastAutoGenerator.create("jdbc:mysql://localhost:3306/ozo_cloud?serverTimezone=GMT%2B8",
                        "root", "root")
                // 全局配置
                .globalConfig(builder -> {
                    builder.author("qiangesoft")
//                            .enableSwagger()
                            .disableOpenDir()
                            .outputDir(projectPath + "/ozo-cloud-system" + "/src/main/java");
                })
                // 包路径配置
                .packageConfig(builder -> {
                    builder.parent("com.ozo.cloud.system")
                            .entity("entity")
                            .mapper("mapper")
                            .service("service")
                            .serviceImpl("service.impl")
                            .pathInfo(map);
                })
                // 策略配置
                .strategyConfig(builder -> {
                    builder
//                            .addInclude("table1", "table2")
                            .entityBuilder()
                            .enableLombok()
//                            .enableTableFieldAnnotation()
                            .controllerBuilder()
                            .enableRestStyle();
                })
                // 使用 Freemarker 模板引擎
                .templateEngine(new FreemarkerTemplateEngine())
                // 执行生成
                .execute();
    }

}
